<?php
/**
 * @var object $data
 */
    if(isset($data)) {
        $hojas = ceil(count($data->records) / 8);
        $j = 0;
        $m = 0;
        for ($k = 1; $k <= $hojas; $k++) { ?>
            <table class="passports" style="page-break-after: always;">
                <?php for (; $j < 8 * $k; $j++) {
                    if (isset($data->records[$j]['certs']) && count($data->records[$j]['certs']) != 0) {
                        $user = $data->records[$j]['certs'];
                        if ($j % 2 == 0) { ?>
                            <tr>
                        <?php } ?>
                        <td class="passport" style=''>
                            <div class="headPasport">
                                <div>
                                    <?php echo $this->Html->image('bosch-logo.png', array('height' => '30px')); ?>
                                </div>
                                <div>
                                    <p><?php echo $data->records[$j]['str']['title']; ?></p>
                                </div>
                                <div class="iconCategorization">
                                    <i class="<?php echo $data->records[$j]['catIcon']; ?>"
                                       style="color: <?php echo $data->records[$j]['catColor']; ?> !important; @media print { color: <?php echo $data->records[$j]['catColor']; ?> !important; }"></i>
                                </div>
                            </div>
                            <div class="bodyPassport">
                                <div>
                                    <div class="mla">
                                        <?php echo $data->records[$j]['nameLine']; ?>
                                    </div>
                                    <div class="numNom">
                                        <?php echo $user[0]['numNom']; ?>
                                    </div>
                                </div>
                                <div class="nomAsc">
                                    <?php echo $user[0]['nameAsc']; ?>
                                </div>
                                <div class="tablaCert">
                                    <?php if (count($user) > 9) {
                                    $length = 18; ?>
                                    <table style="width: 50%">
                                        <?php } else {
                                        $length = 36; ?>
                                        <table style="width: 100%">
                                            <?php } ?>
                                            <?php
                                            $i = 0;
                                            if (isset($user[$i])) {
                                                for (; $i < 9; $i++) {
                                                    if (isset($user[$i])) { ?>
                                                        <tr>
                                                            <td>
                                                                <p class="nameWork"><?php echo $user[$i]['nameWork']; ?></p>
                                                            </td>
                                                            <td>
                                                                <?php if ($user[$i]['sucss'] == '1') { ?>
                                                                    <?php echo $this->Html->image('success.png'); ?>
                                                                <?php } elseif ($user[$i]['train'] == '1') { ?>
                                                                    <?php echo $this->Html->image('proces.png'); ?>
                                                                <?php } ?>
                                                            </td>
                                                            <td>
                                                                <?php if ($user[$i]['sucss'] == '1') { ?>
                                                                    <p class="fechaCert"><?php echo $user[$i]['life']; ?></p>
                                                                <?php } elseif ($user[$i]['train'] == '1') { ?>
                                                                    <p class="fechaFinCert"><?php echo $user[$i]['end']; ?></p>
                                                                <?php } ?>
                                                            </td>
                                                        </tr>
                                                    <?php } else { ?>
                                                        <tr>
                                                            <td>&nbsp;</td>
                                                            <td>&nbsp;</td>
                                                            <td>&nbsp;</td>
                                                        </tr>
                                                    <?php }
                                                }
                                            }
                                            ?>
                                        </table>
                                        <table>
                                            <?php
                                            if (isset($user[$i])) {
                                                for (; $i < 18; $i++) {
                                                    if (isset($user[$i])) { ?>
                                                        <tr>
                                                            <td>
                                                                <p class="nameWork"><?php echo $user[$i]['nameWork']; ?></p>
                                                            </td>
                                                            <td>
                                                                <?php if ($user[$i]['sucss'] == '1') { ?>
                                                                    <?php echo $this->Html->image('success.png'); ?>
                                                                <?php } elseif ($user[$i]['train'] == '1') { ?>
                                                                    <?php echo $this->Html->image('proces.png'); ?>
                                                                <?php } ?>
                                                            </td>
                                                            <td>
                                                                <?php if ($user[$i]['sucss'] == '1') { ?>
                                                                    <p class="fechaCert"><?php echo $user[$i]['life']; ?></p>
                                                                <?php } elseif ($user[$i]['train'] == '1') { ?>
                                                                    <p class="fechaFinCert"><?php echo $user[$i]['end']; ?></p>
                                                                <?php } ?>
                                                            </td>
                                                        </tr>
                                                    <?php } else { ?>
                                                        <tr>
                                                            <td>&nbsp;</td>
                                                            <td>&nbsp;</td>
                                                            <td>&nbsp;</td>
                                                        </tr>
                                                    <?php }
                                                }
                                            }
                                            ?>
                                        </table>
                                </div>
                                <p class="printDate">
                                    Fecha de impresi&oacute;n: <?php echo date('Y-m-d'); ?>
                                </p>
                            </div>
                        </td>
                        <?php if ($j % 2 != 0) { ?>
                            </tr>
                        <?php }
                    } else {
                        if ($j % 2 == 0) { ?>
                            <tr>
                        <?php } ?>
                        <td class="passport"></td>
                        <?php if ($j % 2 != 0) { ?>
                            </tr>
                        <?php }
                    }
                } ?>
            </table>
            <table class="backPassports ">
                <?php for (; $m < 8 * $k; $m++) {
                    if ($m % 2 == 0) {
                        $l = $m + 1; ?>
                        <tr>
                    <?php } else {
                        $l = $m - 1;
                    } ?>
                    <td class="backPassport">
                        <?php if (isset($data->records[$l]['certs']) && count($data->records[$l]['certs']) != 0) { ?>
                        <div class="bodyBPassport">
                            <div>
                                <?php echo $data->records[$l]['str']['msg']; ?>
                            </div>
                            <div class="qrcode" data-code="<?php echo $data->records[$l]['urlQR']; ?>"
                                 data-color="<?php echo $data->records[$l]['catColor']; ?>">
                            </div>
                            <div>
                                <?php if (isset($data->records[$l]['emi'])) { ?>
                                    Elaborado por: <?php echo $data->records[$l]['emi']; ?>
                                <?php } else { ?>
                                    &nbsp;
                                <?php } ?>
                            </div>
                            <?php if (isset($data->records[$l]['emi'])) { ?>
                            <div class="bcd kbarcode" data-codeforbar="<?php echo $data->records[$l]['security']; ?>">
                                <?php } else { ?>
                                <div class="bcd">
                                    <?php } ?>


                                </div>
                            </div>
                            <div class="footBPassport"><?php echo $data->records[$l]['str']['footer']; ?></div>
                            <?php } else { ?>
                                &nbsp;
                            <?php } ?>
                    </td>
                    <?php if ($m % 2 != 0) { ?>
                        </tr>
                    <?php }
                } ?>
            </table>
        <?php }
    }?>